package com.smart.campus.controller;

import com.smart.campus.dto.SysRole;
import com.smart.campus.pojo.PagedResponse;
import com.smart.campus.pojo.ResponseResult;
import com.smart.campus.service.SysRoleServiceFeign;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = "角色管理")
@Slf4j
@RestController
@RequestMapping(value = "sysRole")
public class SysRoleController {
    @Autowired
    private SysRoleServiceFeign sysRoleServiceFeign;

    @RequestMapping(value = "findSysRoleList")
    public ResponseResult<List<SysRole>> findSysRoleList(){
        return new ResponseResult<>(200,"成功", sysRoleServiceFeign.findSysRoleList());
    }
    @RequestMapping(value = "pageRole")
    public ResponseResult<PagedResponse<SysRole>> pageRole(@RequestBody SysRole sysRole, @RequestParam(value = "pageNum")Integer pageNum,@RequestParam(value = "pageSize")Integer pageSize){
        return new ResponseResult<>(200,"成功",sysRoleServiceFeign.pageRole(sysRole,pageNum,pageSize));
    }
    @RequestMapping(value = "addRole")
    public ResponseResult addRole(@RequestBody SysRole sysRole){
        try {
            sysRoleServiceFeign.addRole(sysRole);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
    @RequestMapping(value = "delRole")
    public ResponseResult delRole(@RequestParam(value = "roleId")Integer roleId){
        try {
            sysRoleServiceFeign.delSysRole(roleId);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
    @RequestMapping(value = "findRoleById")
    public ResponseResult<SysRole> findRoleById(@RequestParam(value = "roleId")Integer roleId){
        return new ResponseResult<>(200,"成功",sysRoleServiceFeign.findRoleById(roleId));
    }

    @RequestMapping(value = "updateRole")
    public ResponseResult updateRole(@RequestBody SysRole sysRole){
        try {
            sysRoleServiceFeign.updateRole(sysRole);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
    @RequestMapping(value = "updateRoleStatus")
    public ResponseResult updateRoleStatus(@RequestBody SysRole sysRole){
        try {
            sysRoleServiceFeign.updateRoleStatus(sysRole);
            return new ResponseResult<>(200,"成功");
        } catch (Exception e) {
            e.printStackTrace();
            return new ResponseResult<>(444,"失败");
        }
    }
}
